<template>
    <view class="content">
		<page-head :title="i18n.pages.form"></page-head>
		<image src="../../static/tabbar/return.png" mode="" class="page-return" @tap="back"></image>
		<view class="center">
			<view class="verified">
				<view class="form">
					<view class="form-input">
						<view class="title">{{i18n.center.contact}}</view>
						<m-input class="input" type="text" v-model="contact" :placeholder="i18n.center.contact1" maxlength="20"></m-input>
						
						<view class="title">{{i18n.center.titles}}</view>
						<m-input class="input" type="text" v-model="title" :placeholder="i18n.center.titles1" maxlength="20"></m-input>
						
						<view class="title">{{i18n.center.contents}}</view>
						<textarea v-model="content" :placeholder="i18n.center.contents1" maxlength="200" class="form-textarea" />
						
						<view class="title">{{i18n.center.image}}</view>
						<block v-if="imageSrc">
							<image :src="imageSrc" class="image" mode="widthFix" @click="chooseImage"></image>
						</block>
						
						<block v-else>
							<view  class='img' @click="chooseImage">
								<view class="addfile">{{i18n.center.image2}}</view>
							</view>
						</block>
					</view>
				</view>
				
				<view class="form1">
					<button class="btn-submit" @tap="form" v-if="status == 1">{{i18n.pages.form}}</button>
					<button class="btn-submit" v-else>{{i18n.pages.form}}</button>
				</view>
			</view>
		</view>
		<image :src="back_img" mode="" class="back_img" :style="height"></image>
    </view>
</template>

<script>
	import service from '../../service.js';
	import mInput from '../../components/m-input.vue';
	import pageHead from '../../components/page-head.vue';
	export default {
		computed: {
			i18n () {
				return this.$t('index');
			}
		},
		components: {
			pageHead,
			mInput
        },
		data() {
			return {
				back_img:uni.getStorageSync('page'),
				height:uni.getStorageSync('height'),
				user:uni.getStorageSync('user'),
				contact:'',
				title:'',
				status:1,
				content:'',
				imageSrc: ''
			};
		},
		onShow:function(){
			uni.setNavigationBarTitle({
				title: this.i18n.pages.form
			})
			
		},
		methods:{
			back(){
				uni.navigateBack({
					delta: 1
				});
				/* uni.reLaunch({
					url: '/pages/center/complaint'
				}) */
			},
			chooseImage(){
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album','camera'],
					success: (res) => {
						var imageSrc = res.tempFilePaths[0];
						this.imageSrc = imageSrc;
					}
				});
			},
			form(){
				self = this;
				if (self.contact == '') {
					uni.showToast({
						icon: 'none',
						title: self.i18n.center.contact + self.i18n.center.empty
					});
					return;
				}
				if (self.title == '') {
					uni.showToast({
						icon: 'none',
						title: self.i18n.center.titles + self.i18n.center.empty
					});
					return;
				}
				if (self.content == '') {
					uni.showToast({
						icon: 'none',
						title: self.i18n.center.contents + self.i18n.center.empty
					});
					return;
				}
				if(self.imageSrc == ''){
					uni.showToast({
						icon: 'none',
						title: self.i18n.center.image2
					});
					return;
				}
				uni.showModal({
					content: this.i18n.center.formtext,
					cancelText: this.i18n.main.cancel,
					confirmText: this.i18n.main.confirm,
					confirmColor: '#FFAE00',
					cancelColor: '#D2D2D2',
					success: function(res) {
						if (res.confirm) {
							self.type = 0;
							service.upload(this, service.api.center.submit, {
								'title': self.title,
								'phone': self.contact,
								'content': self.content
							}, self.imageSrc, 'img', function(_self, res) {
								uni.showToast({
									icon: 'none',
									title: res.info
								});
								if(res.code == 1){
									uni.setStorageSync("css",4);
									setTimeout(function(){
										uni.reLaunch({
											url: '/pages/center/complaint',
										});
									},1000);
								}else{
									self.type = 1;
								}
							});
						}
					}
				});
			}
		}
    }
</script>

<style lang="scss">
	page{
		background: #F2F2F2;
	}
	.content{
		padding: 0;
		background: #F2F2F2;
	}
	.center{
		z-index: 30;
		width: calc(100% - 60upx);
		margin: 0 30upx;
	}
	.verified{
		padding: 40upx 0;
		border-radius: 20upx;
		margin: 30upx 0 60upx;
		background: rgba(255,255,255,.7);
	}
	.img{
		width: 100%;
		height: 300upx;
		color: #FFFFFF;
		font-size: 40upx;
		text-align: center;
		line-height: 300upx;
		border-radius: 20upx;
		border: 4upx dashed #DDD;
		background: rgba(250,49,161,.2);
	}
	.image{
		margin: 0;
		border-radius: 20upx;
		width: calc(100% - 8upx);
		border: 4upx dashed #DDD;
	}
	.uni-title{
		width: 100%;
		margin-bottom: 20upx;
	}
	.text2{
		margin: 0 5% 20upx;
		font-size: 32upx;
	}
	.current{
		color: #929292;
		font-size: 32upx;
		line-height: 60upx;
		margin: 30upx 60upx 0;
	}
	.current text{
		color: #00B26A;
		font-size: 36upx;
		line-height: 60upx;
	}
	.reminder{
		color: red;
		margin: 0 40upx;
		padding: 10upx 0;
		font-size: 26upx;
		text-align: center;
		line-height: 30upx;
		background: #ffe9e9;
	}
	.form{
		width: 100%;
		display: flex;
	    flex-wrap: wrap;
		flex-direction: row;
		display: inline-flex;
	}
	.form-input{
		width: calc(100% - 120upx);
		margin: 30upx 60upx 0;
	}
	.form-input .input{
		height: 60upx;
		margin: 0 0 30upx;
		border-radius: 20upx;
		padding: 10upx 20upx;
		width: calc(100% - 40upx);
		background: rgba(250,49,161,.2);
	}
	.form-input .bottom{
		margin-bottom: 30upx;
	}
	.form-textarea{
		color: #FFFFFF;
		height: 210upx;
		font-size: 36upx;
		line-height: 50upx;
		border-radius: 20upx;
		padding: 10upx 30upx;
		margin-bottom: 30upx;
		width: calc(100% - 60upx);
		background: rgba(250,49,161,.2);
	}
	.btn-submit{
		height: 80upx;
		line-height: 80upx;
		margin: 30upx 20% 0;
		color: #FFFFFF;
		background: #6FA9FC;
	}
	.back_img{
		margin: 0;
		height: 100%;
	}
	.addfile{
		margin: auto 0;
		line-height: 100upx;
	}
	.title{
		color: #26C4C0;
		font-size: 32upx;
		line-height: 30upx;
		text-indent: 42upx;
		margin-bottom: 10upx;
	}
</style>